#include<iostream>
#include<string>
#include<unistd.h>
#include<cstring>
#include<cassert>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<sys/stat.h>
#include<fcntl.h>
#include "log.hpp"

using namespace std;

#define PATH_NAME "/home/huangjian"
#define PERMISSIONS 0666
#define SIZE 128
#define FIFO_NAME "./fifo.ipc"


class Init
{
public:
    Init()
    {
        umask(0);
        int n = mkfifo(FIFO_NAME, 0666);
        assert(n == 0);
    }
    ~Init()
    {
        unlink(FIFO_NAME);
    }

};

int openFIFO(std::string pathName, int flags)
{
    int fd = open(pathName.c_str(), flags);
    cout << fd ;
    assert(fd != -1);
    return fd;
}
void Wait(int fd)
{
    uint32_t temp = 0;
    ssize_t s = read(fd, &temp, sizeof(uint32_t));//读取管道文件数据，没有写就阻塞
    assert(s == sizeof(uint32_t));
}

void Signal(int fd)
{
    uint32_t temp = 1;
    ssize_t s = write(fd, &temp, sizeof(uint32_t));
    assert(s == sizeof(uint32_t));
}

void CloseFD(int fd)
{
    close(fd);
}